#ifndef CDIALOG_H
#define CDIALOG_H

#include "CDialogBar.h"
#include "CTopWidget.h"

#include <QEventLoop>

class CDialog : public CTopWidget {
    Q_OBJECT
public:
    explicit CDialog(QWidget *parent = nullptr);
    ~CDialog();

private:
    void init();

public:
    int exec(Qt::WindowModality modal = Qt::ApplicationModal);

    bool titleVisible() const;
    void setTitleVisible(bool titleVisible);

protected:
    int m_code;
    QEventLoop m_loop;

    virtual void prepareExec();
    virtual bool acceptClose();

private:
    CDialogBar *m_titleBar;

    void handleClose();

protected:
    bool isMouseOnCaption() const override;
    bool isNative() const override;

    void setNative(bool value) override;

    void windowTitleChangeEvent(QEvent *event) override;

    void closeEvent(QCloseEvent *event) override;
    bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;

signals:
};

#endif // CDIALOG_H
